;solution for euler 24



(defun nth-permutation (n inseq outseq)
	(if (> (length inseq) 1)
		(let (choice)
			(setq choice (elt inseq (mod (floor (/ n (! (- (length inseq) 1)))) (length inseq))))
			(setq outseq (concatenate 'string outseq (string choice)))
			(setq inseq (remove choice inseq))
			(return-from nth-permutation (nth-permutation n inseq outseq)))
		(let (choice)
			(setq choice (elt inseq 0))
			(setq outseq (concatenate 'string outseq (string choice)))
			(setq inseq (remove choice inseq))
			(return-from nth-permutation outseq))))
		
(defun solve-euler24 ()
	(format t "Euler 24: ~a" (nth-permutation (- 1000000 1) "0123456789" "")))